Writing Testsuites
Pike includes a set of scripts to generate and run testsuites. While the primary purpose of these scripts is to test the Pike interpreter itself, you can easily use them to test your own code.This document describes the tools, as well as the syntax for writing tests. Testing toolsThe two tools that are included with Pike are called mktestsuite and test_pike.mktestsuiteThe mktestsuite script is a simple shell script that uses M4 to convert a testsuite input file into a testsuite that can be run by test_pike.pike. This script is found in $PIKE/include/pike.Usage:mktestsuite testsuite.in > testsuite pike test_pike testuitefile Available test typesIn general, there are two forms of each type of test; one takes as its argument a set of statements that when run, will be placed within a function body and run. The other, denoted with a _any suffix, accepts as its argument(s) any block of Pike code, such as class definitions and multiple function definitions.test_anyUsage:test_any([[a]], b) test_any([[ int f (int i) {i = 0; return i;}; return f (1); ]],0) test_any_equal([[a]], b) test_any_equal([[ class Foo {int foo();}; return indices(Foo()); ]], ({"foo"})) test_eq(a, b) test_eq('u117f', 0x117f) test_equal(a, b) test_equal(mtest_m,copy_value(mtest_m)) test_do(a) test_do([[ void foo (int i) { multiset res = (<>); if (i) res = res; }; foo (1); ]]) test_true(a) test_true("A" == upper_case("a")) test_false(a) test_false("A" == "a") test_compile([[a]]) test_compile([[ Stdio.File foo=Stdio.File(); ]]) test_compile_any([[a]]) test_compile_any([[ void foo() { Stdio.File bar(int x, int y) { return 0; }; } ]]) test_compile_error([[a]]) test_compile_error([[ string a="x"; int b; b="x"*17; ]]) test_compile_error_any([[a]]) test_compile_error_any([[ mixed foo; mapping query_variables() { return ([]); }; mixed foo(mixed bar) { return 1/foo; } ]]) test_compile_warning test_compile_warning_any test_eval_error test_define_program,[[DOTEST(RUN,dnl test_program, [[DOTEST(TRUE,dnl test_program_eq, [[DOTEST(EQ,dnl test_program_equal, [[DOTEST(EQUAL,dnl test_tests, [[DOTEST(RUNCT,dnl cond,dnl [[CONDITION]],[[COND $1 [[CONDITION]],[[]]) cond_resolv,[[cond([[master()->resolv(dnl ifefun,[[cond([[all_constants()->$1]],[[$2]])]]) nonregression,[[ifefun(regression,[[$1]])]]) TESTNO,0) [[test_cmp]],[[ [[test_cmp3]],[[ Powered by PikeWiki2 |
|||
gotpike.org | Copyright © 2004 - 2009 | Pike is a trademark of Department of Computer and Information Science, Linköping University |